import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import Unocss from 'unocss/vite'

export default defineConfig({
  base: process.env.NODE_ENV === 'production' && process.env.VITE_PUBLIC_PATH ? process.env.VITE_PUBLIC_PATH : '/',
  plugins: [
    vue(),
    Unocss(),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  server: {
    port: 9010,
    cors: true,
    origin: 'http://localhost:9010',
    allowedHosts: [
      'web3.roginx.ink',
      'localhost',
    ],
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    proxy: {
      '/api': {
        target: 'http://localhost:9011',
        changeOrigin: true,
        // 保留 /api 前缀，因为后端路由需要 /api 前缀
      },
    }
  },
  build: {
    commonjsOptions: {
      esmExternals: true 
    },
    rollupOptions: {
      output: {
        entryFileNames: 'js/[name].js',
        chunkFileNames: 'js/[name].[hash].js',
        assetFileNames: 'assets/[name].[hash].[ext]'
      }
    },
    target: 'esnext',
    minify: 'terser'
  }
})

